/// Setting up the ANES File for presidential coalitions  

use "/Users/joshuazingher/Desktop/Prospectus /anes_cdfdta/anes coalitions .dta"

sort year

rename VCF0704 presvote

rename VCF0703 voted

/// Generating total Female respondants by year

by year: egen femaleresp = count(gender) if gender == 2

/// Generating total number of Female voters by year


by year: egen Femalevoted = count(voted) if gender==2 & voted==3

/// Generating total number of Latnio non-voters by year

by year: egen FemaleNvoted = count(voted) if voted==0 & gender==2 | voted==1 & gender==2 | voted==2 & gender==2

/// Generating total number of non-Female voters by year

by year: egen NFemalevoted = count(voted) if gender~=2 & voted==3

/// Generating total number of non-Female non-voters by year

by year: egen NFemaleNvoted = count(voted) if gender~=2 & voted==0 | gender~=2 & voted==1 | gender~=2 & voted==2

/// filling in the blanks

by year: egen femalevoted = max(Femalevoted)
by year: egen femaleNvoted = max(FemaleNvoted)
by year: egen Nfemalevoted = max(NFemalevoted)
by year: egen NfemaleNvoted = max(NFemaleNvoted)




/// Generating % Female TO with Mosteller Correction

gen N = 1
gen a = [femalevoted * NfemaleNvoted] / [femaleNvoted * Nfemalevoted]


///Generating filler vars

gen aminone =(a-1)
gen AFemaleplusTO = (AFemale+aTO)
gen aFemaleTO=(a*AFemale*aTO)

gen CFemaleTO = 1/ (2*(aminone)) * (N+(aminone*AFemaleplusTO) - sqrt((N+aminone*AFemaleplusTO)*(N+aminone*AFemaleplusTO) - (4*(aminone*aFemaleTO))))

///Adjusting TO for the formula

replace CFemaleTO = CFemaleTO/AFemale



/// Moving to Partisanship - Generating Female Democratic Vote total by year

by year: egen Femaledem = count(gender) if presvote==1 & gender==2

/// Generating Female Non-Democratic Vote by Year

by year: egen FemaleNdem = count(gender) if presvote==2 & gender==2

// Generating non-Female Democratic Vote total by year

by year: egen NFemaledem = count(gender) if presvote==1 & gender~=2

/// Generating non-Female non-Democratic vote total by year

by year: egen NFemaleNdem = count(gender) if presvote==2 & gender~=2

/// filling in the blanks

by year: egen femaleDem = max(Femaledem)
by year: egen femaleNDem = max(FemaleNdem)
by year: egen NfemaleDem = max(NFemaledem)
by year: egen NfemaleNDem = max(NFemaleNdem)

/// Generation % Female Democrat with Mosteller Correction

gen A = (femaleDem*NfemaleNDem)/(femaleNDem*NfemaleDem)
gen Aminone =(A-1)
gen AFemaleplusDem = (AFemale+ADem)
gen AFemaleDem=(A*AFemale*ADem)
gen CFemaleDem = 1/(2*(Aminone)) * (N+(Aminone*AFemaleplusDem) - sqrt((N+Aminone*AFemaleplusDem)*(N+Aminone*AFemaleplusDem) - (4*(Aminone*AFemaleDem))))

replace CFemaleDem = CFemaleDem/AFemale


/// Generating number of ANES respondents by year

by year: egen totalresp = count (VCF0006a)


/// Coalition Contribution

gen femalecoalcontrib = (CFemaleTO* CFemaleDem *AFemale)/(aTO*ADem)



